@extends("ogreencard/layout/layout")
@section("h1","卡券管理")
@section("h2","卡券列表")
@section("content")
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
					<div class="layui-card-header">
						<form class="layui-form layui-col-space5" enctype="multipart/form-data" action="importCardExcel" method="post">
							<input type="hidden" id="token" name="_token" value="{{csrf_token()}}">
							<a href="/ogreencard/file/cards.xlsx" class="layui-btn layui-btn-warm" target="_blank"> <i class="layui-icon">&#xe601;</i>下载模板</a>
							<div class="layui-input-inline layui-show-xs-block"><input type="file" class="layui-btn" accept=".xlsx,.xls" name="excelfile"></div>
							<div class="layui-input-inline layui-show-xs-block">
								<button type="submit" class="layui-btn" id="upload"><i class="layui-icon">&#xe67c;</i>上传表格</button>
							</div>
						</form>
					</div>

                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>卡号</th>
                                <th>密码</th>
                                <th>积分数</th>
                                <th>类型</th>
								<th>提示</th>
{{--                                <th>操作</th>--}}
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($cards as $card)
                                <tr>

                                    <td>{{$card[0]}}</td>
                                    <td>{{$card[1]}}</td>
                                    <td>{{$card[2]}}</td>
                                    <td>{{$card[3]==1?'中行':'内部'}}</td>
									<td class="x-red">{{$card[4]}}</td>
{{--                                    <td class="td-manage">--}}
{{--										<a class="layui-btn layui-btn-sm layui-btn-danger" title="作废" onclick="member_del(this)" href="javascript:;">--}}
{{--											<i class="layui-icon">&#xe640;</i>--}}
{{--										</a>--}}
{{--                                    </td>--}}
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
						@if($submit)
						<div class="layui-card-footer" style="text-align: center;padding:10px 0;">
							<div class="layui-btn btn-primary" onclick="submitCard()">确定导入</div>
						</div>
						@endif
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
		var cards = JSON.parse('{!! json_encode($cards) !!}');
		console.log(cards);
		layui.use(['laydate','form','upload'], function(){
				var laydate = layui.laydate;
				var  form = layui.form;
				var upload = layui.upload;

				var $ = layui.jquery;
				// 监听全选
				form.on('checkbox(checkall)', function(data){

						if(data.elem.checked){
								$('tbody input').prop('checked',true);
						}else{
								$('tbody input').prop('checked',false);
						}
						form.render('checkbox');
				});
		});

		/*用户-删除*/
		function member_del(obj,id){

				layer.prompt({
						formType: 2,
						value: '',
						title: '请说明作废理由',
						area: ['300px', '150px'] //自定义文本域宽高
				}, function(value, index, elem){
						$ = layui.jquery;

						$.get({
								url:'./cardDel?id='+id+"&note="+value,
								success:function(){
										//$(obj).parents("tr").remove();
										layer.msg('已删除!',{icon:1,time:1000},function()
										{
												location.reload();
										});
								}
						});
						//layer.close(index);
				});
		}



		function delAll (argument) {
				var ids = [];

				// 获取选中的id
				$('tbody input').each(function(index, el) {
						if($(this).prop('checked'))
						{
								ids.push($(this).val())
						}
				});
				if(ids.length ==0) return;
				layer.prompt({
						formType: 2,
						value: '',
						title: '请说明作废理由',
						area: ['300px', '150px'] //自定义文本域宽高
				}, function(value, index, elem){
						$ = layui.jquery;

						$.get({
								url:'./cardDel?note='+value+'&id='+ids.join(","),
								success:function(){
										layer.msg('已作废!',{icon:1,time:1000},function()
										{
												location.reload();
										});
								}
						});
				});
		}

		function submitCard() {
			var load = layer.load('导入中·····');
			$.post({
				url:'./importCard',
				data:{
					_token:$('#token').val(),
					cards:cards,
				},
				success(res){
					console.log(res);
					layer.close(load);
					if(res.code == 200){
						layer.msg(res.msg,{icon:6});
					}else{
						layer.msg(res.msg,{icon:7});
					}
				},
				fail(res){
					layer.close(load);
					layer.msg('导入失败',{icon:7});
				}
			})
		}
    </script>

@endsection